﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using BO = HZU.ZP.Domain.Model.Resume;
using VO = HZU.ZP.Data.Models.Resume;

namespace HZU.ZP.Domain.ServiceImpl.Mappers.Resume
{
    public class EducationExperienceMapper
    {
        public VO.EducationExperience MapToDao(BO.EducationExperience model)
        {
            if (model == null)
                return null;

            VO.EducationExperience result = new VO.EducationExperience();
            Type moType = model.GetType();
            Type reType = result.GetType();
            PropertyInfo[] moProInfo = moType.GetProperties();
            PropertyInfo[] reProInfo = reType.GetProperties();
            foreach (PropertyInfo reInfo in reProInfo)
            {
                foreach (PropertyInfo moInfo in moProInfo)
                {
                    if (reInfo.Name.Equals(moInfo.Name))
                    {
                        reInfo.SetValue(result, moInfo.GetValue(model, null), null);
                    }
                }
            }
            return result;
        }

        public BO.EducationExperience MapToDomain(VO.EducationExperience model)
        {
            if (model == null)
                return null;
            BO.EducationExperience result = new BO.EducationExperience();
            Type moType = model.GetType();
            Type reType = result.GetType();
            PropertyInfo[] moProInfo = moType.GetProperties();
            PropertyInfo[] reProInfo = reType.GetProperties();
            foreach (PropertyInfo reInfo in reProInfo)
            {
                foreach (PropertyInfo moInfo in moProInfo)
                {
                    if (reInfo.Name.Equals(moInfo.Name))
                    {
                        reInfo.SetValue(result, moInfo.GetValue(model, null), null);
                    }
                }
            }
            return result;
        }
        public IList<BO.EducationExperience> MapToDomainList(IEnumerable<VO.EducationExperience> modelList)
        {
            if (modelList == null)
                return null;

            return modelList.Select(m => MapToDomain(m)).ToList();
        }
    }
}
